import { queryLoginUser } from '@/api'
// import { mobileExchange } from '@/api'
import moment from 'moment'
var urlParams = new URLSearchParams(location.search)
var tokenAuthKey = urlParams.get('authCode')
export default {
	state: {
		token: localStorage.getItem(tokenAuthKey),
		userInfo: null
		// total: {}
	},

	mutations: {
		SET_TOKEN(state, token) {
			state.token = token
			localStorage.setItem(tokenAuthKey, token)
		},
		SET_USER_INFO(state, userInfo) {
			state.userInfo = userInfo
		}
	},

	actions: {
		login({ commit, state, dispatch }, servData) {
			var token = servData['Admin-Token']
			var user = servData['user']
			commit('SET_TOKEN', token)
			commit('SET_USER_INFO', user)
		},
		async getUserInfo({ commit, state, dispatch }, userInfo) {
			await queryLoginUser().then((res) => {
				commit('SET_USER_INFO', res.data)
			})
		},
		logout({ commit }) {
			commit('SET_TOKEN', '')
			commit('SET_USER_INFO', null)
			location.reload()
		}
	}
}
